<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
class Course extends  Base
{
    public function initialize(){
        parent::initialize();
    }

    public function info($input)
    {
          $course = Controller('Course', 'logic');
          $res = $course->cinfo($input);
          return $this->print_result($res);
    }
    // 课时对应的课程信息
    public function classtimeinfo($input)
    {
          $course = Controller('Course', 'logic');
          $res = $course->classtimecourseinfo($input);
          return $this->print_result($res);
    }
   public function ajaxList(){
        $input = $this->request->param(false);
        $page_limit      = isset($input['length'])?$input['length']:10;
        $page_start      = isset($input['start'])?$input['start']:0;
        $p = 1;
        if ($page_start > 0) {
            $p = ceil($page_start / ($page_limit - 1));
        }
        $sid = isset($input['sid'])?$input['sid']:0;
        if (!$sid) {
          $this->return_data['Msg'] = "缺少必填信息";
          return $this->print_result($this->return_data);
        }
        $store= Db::name('store')->where([['id','=',$sid]])->find();
        if (!$store) {
          $this->return_data['Msg'] = "无此门店";
          return $this->print_result($this->return_data);
        }
        $where = [];
        $where[] = ['sid','=',$sid];
        $where[] = ['status','=',1];
        $field = 'id,sid,name,summary,pic,description,status,isindex,ordernum,createtime,updatetime,periods,class_time,teacher_id,teacher_name,classroom_id,classroom_name,classes_id,classes_name,address';
        // $count=Db::name('course')->where($where)->count();
        $list  = Db::name('course')
              ->field($field)
              ->where($where)
              ->order('ordernum asc,id desc')
              ->group('name')
              ->page($p, $page_limit)->select();
        foreach($list as $k=>$v){
          $list[$k]['cover'] = get_newpic_url($v['pic']);
        }
        $count=count($list);

        $this->return_data['Msg']='OK';
        $this->return_data['Code']=0;
        $this->return_data['Data']=['course'=>$list];
        return $this->print_result($this->return_data);
   }

    public function my_course_info($input)
    {
          $course = Controller('Course', 'logic');
          $res = $course->my_course_info($input);
          return $this->print_result($res);
    }

}
